<!--头部公共部分-->
{include file="common/header" /}
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a>首页</a>
        <a>财务</a>
        <a>
          <cite>收款管理</cite></a>
      </span>
    <a class="layui-btn layui-btn-xs layui-btn-small" style="float:right;margin-top: 10px;"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon layui-icon-refresh"></i> </a>
</div>
<div class="x-body">
    <div class="layui-row">
        <div class="layui-form layui-col-md12 x-so layui-form-pane">
            <div class="layui-input-inline">
                <select name="campus_id" lay-search="">
                    <option value="">选择收款校区</option>
                    {volist name="campus" id="campu"}
                    <option value="{$campu.id}">{$campu.campus_name}</option>
                    {/volist}
                </select>
            </div>


            <div class="layui-input-inline">
                <input type="text" name="receipt_number" placeholder="收款凭证" autocomplete="off" class="layui-input">
            </div>

            <div class="layui-input-inline">
                <input type="text" name="contract_number" placeholder="订单编号" autocomplete="off" class="layui-input">
            </div>

            <div class="layui-input-inline">
                <input type="text" class="layui-input" style="width: auto" placeholder="收款日期" name="paydate" id="start">
            </div>

            <div class="layui-input-inline">
                <button class="layui-btn" data-type="reload" id="search">筛选</button>
                <button class="layui-btn layui-btn-danger" id="clear">重置</button>
            </div>
        </div>
    </div>
    <!--<div class="site-demo-button" lay-filter="selBtn" id="typeclass">-->
        <!--<button class="layui-btn site-demo-active layui-btn-warm" data-type="all">全部</button>-->
        <!--<button class="layui-btn site-demo-active" data-type="2">未付款</button>-->
    <!--</div>-->
    <table class="layui-table" id="datalist" lay-filter="Event"></table>
</div>
<script type="text/html" id="barTable">
    {{# if(d.status == 1 && d.payment_method == '现金'){ }}
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="check">审核</a>
    {{# } else if(d.status == 2 && d.payment_method == '现金') { }}
    <a class="layui-btn layui-btn-xs layui-btn-disabled">已审核</a>
    {{# } }}
    {{# if(d.status == 2 && d.payment_method != '现金'){ }}
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="detail">支付凭证</a>
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="refund">退款</a>
    {{# } else if(d.status == 1 && d.payment_method != '现金') { }}
    <a class="layui-btn layui-btn-xs layui-btn-disabled">未支付</a>
    {{# } else if(d.status == 3 && d.payment_method != '现金') { }}
    <a class="layui-btn layui-btn-xs layui-btn-disabled">已退款</a>
    {{# } }}
</script>
<!--底部公共部分-->
{include file="common/footer" /}
<script>
    layui.use(['table', 'element', 'laydate', 'layer'], function () {
        var table = layui.table,
            laydate = layui.laydate,
            element = layui.element,
            layer = layui.layer,
            $ = layui.$;
        let loading = layer.load();
            //日期
            laydate.render({
                elem: '#start',
                range:true
                ,trigger: 'click'
            });

        //方法级渲染
        var tableIns = table.render({
            elem: '#datalist',
            url: '{:url("finance/receivables_management")}',
            toolbar: 'true', //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
            defaultToolbar: ['print', 'exports'], // 筛选图标
            method: 'POST',
            loading: true,
            cols: [[
             /***   {field: 'id', title: 'ID', width: 100, align: 'center'},***/
                {field: 'receipt_number', title: '收款凭证号',style:'color:#01AAED;font-weight: bold;', width: 150, align: 'center'},
                {field: 'contract_number', title: '订单编号',   width: 200, align: 'center'},
                {field: 'campus_id', title: '收款校区', width: 120, align: 'center'},
                {field: 'student_name', title: '学员姓名', width: 90, align: 'center'},
                {field: 'grade', title: '学员年级', width: 90, align: 'center'},
                {field: 'paydate', title: '收款日期', width: 110, align: 'center'},
                {field: 'amount', title: '收款金额', style:'color:#01AAED;font-weight: bold;', width: 90, align: 'center'},
                {field: 'payment_method', title: '支付方式',style:'font-weight: bold;', width: 150, align: 'center'},
             /***   {field: 'flow_number', title: '流水号', width: 150, align: 'center'},**/
                {field: 'payee', title: '收款人', width: 90, align: 'center'},
                {title: '操作/状态', fixed: 'right', width: 200, align: 'center', toolbar: '#barTable'},
            ]],
            page: true,
            title: '收款管理报表',
            limits: [10,20,30,40,50,60,70,80,90,10000000],
            height: 'full-230',
            done: function (res, curr, count) {
                layer.close(loading);
                //如果是异步请求数据方式，res即为你接口返回的信息。
                //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
            }
        });

        //订单分类选择
        $('.site-demo-active').on('click', function () {
            $('#typeclass').find('button').removeClass('layui-btn-warm');
            $(this).addClass('layui-btn-warm');
            var type = $(this).data('type');
            tableIns.reload({
                where: {
                    'type': type
                }
            });
        });

        //监听工具条
        table.on('tool(Event)', function (obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值
            if(layEvent === 'detail') { //查看
                location.href = "{:url('Finance/payment_voucher')}?id="+data.id;
            }else if (layEvent === 'check') {
                if(data.contract_number === '合计'){
                    layer.msg('【合计】栏目不可选中');
                    return;
                }
                var status;
                if (data.status === 1) {
                    status = 2;
                } else {
                    status = 1;
                }
                layer.confirm('确认是否审核通过？', {icon: 3, title:'审核确认'}, function(index) {
                    //激活与禁用状态改变
                    $.post("{:url('finance/receivables_check_status')}", {
                        id: data.id,
                        status: status
                    }, function (rJson) {
                        if (rJson.code === 0) {
                            layer.msg(rJson.msg, {
                                time: 2000
                            });
                            setTimeout(function () {
                                location.reload();
                            }, 2000)
                        } else {
                            layer.msg(rJson.msg, {
                                icon: 2,
                                time: 2000
                            });
                        }
                    }, "json")
                });
            }else if (layEvent === 'refund') {
                if(data.contract_number === '合计'){
                    layer.msg('【合计】栏目不可选中');
                    return;
                }
                let url = "{:url('Finance/refund')}?receipt_number="+data.receipt_number;
                layer.open({
                    type: 2,
                    skin: 'layui-layer-lan',
                    closeBtn: 2,
                    title: '退款',
                    area: ['50%', '60%'],
                    shadeClose: false,
                    content: url,
                });
            }
        });
        //搜索项
        $('#search').click(function () {
            var field = {};
            field.contract_number = $('input[name=contract_number]').val();
            field.receipt_number = $('input[name=receipt_number]').val();
            field.campus_id = $('select[name=campus_id] option:selected').val();
            var create_date_rang = $('input[name=paydate]').val();
            if(create_date_rang.length > 0){
                strs_date=create_date_rang.split("-"); //字符分割
                field.start_date = strs_date[0]+'-'+strs_date[1]+'-'+strs_date[2];
                field.end_date = strs_date[3]+'-'+strs_date[4]+'-'+strs_date[5];
            }

            console.log(field);
            tableIns.reload({
                where: field,
                method: 'POST',
                page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });
        //清除
        $('#clear').click(function () {
            $('.layui-form-pane').find('.layui-input-inline').each(function (index, element) {
                $(element).find('input[type=text]').val('');
                $(element).find('select').val('');
            })
            tableIns.reload({
                where: {
                    'contract_number': '',
                    'receipt_number': '',
                    'campus_id': '',
                    'paydate': '',
                },
                page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });
    });
</script>
<script>var _hmt = _hmt || [];
(function () {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
})();</script>
